let DateUtil = require("../../utils/dateUtil");
function PlayerScore() {
    this.uid = 0;
    this.nickname = "";
    this.score = 0;
}

PlayerScore.prototype.toBSON = function() {
    return {
        uid : this.uid,
        nickname: this.nickname,
        score : this.score
    };
};

PlayerScore.prototype.toJSON = function () {
    return {
        uid : this.uid,
        nickname: this.nickname,
        score : this.score
    };
};

module.exports.create = function(uid, nickname, score) {
    let playerScore = new PlayerScore();
    playerScore.uid = uid;
    playerScore.nickname = nickname;
    playerScore.score = score;
    return playerScore;
};

module.exports.loadFromDocument = function (document) {
    let playerScore = new PlayerScore();
    playerScore.uid = document["uid"];
    playerScore.nickname = document["nickname"];
    playerScore.score = +document["score"];
    if (isNaN(playerScore.score)) {
        playerScore.score = 0;
    }
    return playerScore;
};
